local yitiao = fk.CreateSkill {
  name = "lingling__yitiao",
}

Fk:loadTranslationTable {
  ["lingling__yitiao"] = "一条鞭法",
  [":lingling__yitiao"] = "当你受到伤害后，你可以与伤害来源各摸三张牌，然后其弃置两张牌，你弃置X张牌。（X为你的体力值）",
}

yitiao:addEffect(fk.Damaged, {
  can_trigger = function(self, event, target, player, data)
    return target == player and player:hasSkill(yitiao.name) and data.from
  end,
  on_use = function(self, event, target, player, data)
    local room = player.room
    player:drawCards(3, yitiao.name)
    if not data.from.dead then
      data.from:drawCards(3, yitiao.name)
    end
    if not data.from.dead then
      local cards = table.filter(data.from:getCardIds("he"), function(id)
        return not data.from:prohibitDiscard(id)
      end)
      if #cards > 2 then
        cards = room:askToDiscard(data.from, {
          min_num = 2,
          max_num = 2,
          include_equip = true,
          skill_name = yitiao.name,
          cancelable = false,
          skip = true
        })
      end
      room:throwCard(cards,yitiao.name,data.from)
    end
    if not player.dead then
      local cards = table.filter(player:getCardIds("he"), function(id)
        return not player:prohibitDiscard(id)
      end)
      if #cards > player.hp then
        cards = room:askToDiscard(player, {
          min_num = player.hp,
          max_num = player.hp,
          include_equip = true,
          skill_name = yitiao.name,
          cancelable = false,
          skip = true
        })
      end
      room:throwCard(cards,yitiao.name,player)
    end
  end,
})

return yitiao
